package com.jolink.omiis.wechat.redis;

import java.util.List;
import java.util.Map;
import java.util.Set;

import redis.clients.jedis.JedisPubSub;

public interface IRedisProcessor {

	void subscribe(JedisPubSub listener, String... channels) throws Exception;

	/**
	 * 获取Map集合
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	Map<String, String> hgetall(String key) throws Exception;

	String hdel(String key, String... fields) throws Exception;

	String del(String... keys) throws Exception;

	/**
	 * key-value存入集合中
	 * 
	 * @param key
	 * @param row
	 * @return
	 * @throws Exception
	 */
	String hmset(String key, Map<String, String> row) throws Exception;

	String hmset(String key, String... fields) throws Exception;

	/**
	 * @param key
	 * @param field
	 * @param value
	 * @return
	 * @throws Exception
	 */
	String hset(String key, String field, String value) throws Exception;

	/**
	 * 指定key是否存在
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	boolean exists(String key) throws Exception;

	/**
	 * 设定key在N秒后失效
	 * 
	 * @param key
	 * @param seconds
	 * @return
	 * @throws Exception
	 */
	String expireKey(String key, int seconds) throws Exception;

	/**
	 * 存储key-value
	 * 
	 * @param key
	 * @param value
	 * @return
	 * @throws Exception
	 */
	String set(String key, String value) throws Exception;

	String incr(String key) throws Exception;

	/**
	 * 获取key-value
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	String get(String key) throws Exception;

	/**
	 * 对象序列化到redis中存储
	 * 
	 * @param key
	 * @param bean
	 * @return
	 * @throws Exception
	 */
	<T> String set(String key, T bean) throws Exception;

	/**
	 * 对象从redis反序列化
	 * 
	 * @param key
	 * @param type
	 * @return
	 * @throws Exception
	 */
	<T> T get(String key, Class<T> type) throws Exception;

	/**
	 * 获取value，设定超时时间
	 * 
	 * @param timeout
	 * @param keys
	 * @return
	 * @throws Exception
	 */
	List<String> blpop(int timeout, String... keys) throws Exception;

	/**
	 * 从集合中获取value，设定超时时间
	 * 
	 * @param timeout
	 * @param keys
	 * @return
	 * @throws Exception
	 */
	List<String> brpop(int timeout, String... keys) throws Exception;

	/**
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	String rpop(String key) throws Exception;

	/**
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	String lpop(String key) throws Exception;

	/**
	 * 统计列表长度
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	String llen(String key) throws Exception;

	/**
	 * 放入列表第一个
	 * 
	 * @param key
	 * @param values
	 * @return
	 * @throws Exception
	 */
	String lpush(String key, String... values) throws Exception;

	/**
	 * 存入列表（ArrayList、LinkedList）
	 * 
	 * @param key
	 * @param values
	 * @return
	 * @throws Exception
	 */
	String lpush(String key, List<String> values) throws Exception;

	String lrem(String key, String value) throws Exception;

	/**
	 * 放入列表末尾
	 * 
	 * @param key
	 * @param values
	 * @return
	 * @throws Exception
	 */
	String rpush(String key, String... values) throws Exception;

	/**
	 * @param key
	 * @param values
	 * @return
	 * @throws Exception
	 */
	String sadd(String key, String... values) throws Exception;

	/**
	 * @param key
	 * @return
	 * @throws Exception
	 */
	String scard(String key) throws Exception;

	/**
	 * 根据key获取集合
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	Set<String> smembers(String key) throws Exception;

	/**
	 * @param key
	 * @return
	 * @throws Exception
	 */
	String spop(String key) throws Exception;

	/**
	 * 添加有序集合
	 * 
	 * @param key
	 * @param values
	 *            Double类似于权值，可以用作排序
	 * @return
	 * @throws Exception
	 */
	String zadd(String key, Map<String, Double> values) throws Exception;

	/**
	 * @param key
	 * @return
	 * @throws Exception
	 */
	String zcard(String key) throws Exception;

	String[] keys(String keyPattern) throws Exception;

	String srem(String key, String... members) throws Exception;

}
